import React, { useCallback } from 'react'
import { View, Text } from '@tarojs/components'
import i18n from '@I18N'
import UserAvatar from '@COMPONENTS/User/UserAvatar'
import UserName from '@COMPONENTS/User/UserName'
import UserDesc from '@COMPONENTS/User/UserDesc'
import { HOSPITAL_LEVEL, HOSPITAL_LEVEL_ENUMS } from '@CONSTANTS/group'
import { getHighlightHtml } from '@UTILS/highlight'
import './RecommendUserCard.scss'

export default function RecommendUserCard({
  data, language, onClick, onLineDesc, highlight = [], showLabel, onlyGroup
}) {
  const {
    p8Id, Expertise, Affiliation = {}, Visited
  } = data
  const { HospitalLevel } = Affiliation
  const showLevel = HospitalLevel === HOSPITAL_LEVEL_ENUMS.ThirdA
  let expertiseHtml = Expertise?.[language]
  if (highlight?.length) {
    expertiseHtml = getHighlightHtml(expertiseHtml, highlight)
  }

  const onClickUser = useCallback(() => {
    onClick && onClick(p8Id)
  }, [p8Id, onClick])
  return (
    <View className="user-card" onClick={onClickUser}>
      <View className="user-info">
        <View className="user-info-identity">
          <UserName data={data} language={language} highlight={highlight} />
          <UserDesc data={data} language={language} oneLine={onLineDesc} highlight={highlight} onlyGroup={onlyGroup} />
        </View>
        <UserAvatar data={data} />
      </View>
      {!!showLabel && (
        <View className="labels">
          {showLevel && <Text className="label default-label">{HOSPITAL_LEVEL[HospitalLevel][language]}</Text>}
          <Text className="label">{i18n.common.verified()}</Text>
          {Visited && <Text className="label visited-label">{i18n.doctor.visited()}</Text>}
        </View>
      )}
      <View className="user-major-container">
        <Text className="user-major">
          {`${i18n.doctor.expertise()}：`}
          <Text>{expertiseHtml}</Text>
        </Text>
      </View>
    </View>
  )
}

RecommendUserCard.defaultProps = {
  data: {}
}
RecommendUserCard.externalClasses = ['container-class', 'card-class', 'custom-expertise']
